/**
 * Projet Multicast Bidois Morgan & Thomas Nunes
 *
 */
package Engine;

/**
 *
 * @author thomas The flag is a part of a message indicated his type
 */
public class Flag {

    private TypeMessage type;

    /**
     * get the number corresponding to the type of flag
     *
     * @return the number coresponding to the flag
     */
    public short getShort() {
        switch (type) {
            case NORMAL:
                return 1;
            case SOMEONE_LEAVE:
                return 2;
            case START_BURST:
                return 3;
            case STOP_BURST:
                return 4;
            case ACK:
                return 5;
            case NEW_CONNECTION:
                return 6;
            case SEND_DIRECTORY:
                return 7;
            case SEND_ID:
                return 8;
            case CLIENT_SERVERSOCKET_READY:
                return 9;
            case BEGIN_CONNECTION:
                return 10;

        }
        return 0;
    }

    public Flag(TypeMessage typeFlag) {
        this.type = typeFlag;
    }

    public Flag(short indice) {

        switch (indice) {
            case 1:
                this.type = TypeMessage.NORMAL;
                break;
            case 6:
                this.type = TypeMessage.NEW_CONNECTION;
                break;
            case 2:
                this.type = TypeMessage.SOMEONE_LEAVE;
                break;
            case 3:
                this.type = TypeMessage.START_BURST;
                break;
            case 4:
                this.type = TypeMessage.STOP_BURST;
                break;
            case 5:
                this.type = TypeMessage.ACK;
                break;
            case 7:
                this.type = TypeMessage.SEND_DIRECTORY;
                break;
            case 8:
                this.type = TypeMessage.SEND_ID;
                break;
            case 9:
                this.type = TypeMessage.CLIENT_SERVERSOCKET_READY;
                break;
            case 10:
                this.type = TypeMessage.BEGIN_CONNECTION;
                break;
            default:
                this.type = TypeMessage.UNKNOWN;
        }
    }

    public TypeMessage getType() {
        return type;
    }

    public void setType(TypeMessage type) {
        this.type = type;
    }

    @Override
    public String toString() {
        return this.getType().toString();
    }
}
